#include "QueryPlanNode.h"

GroupByNode::GroupByNode(int inPipeId, int outPipeId, OrderMaker *groupAtts,
		Function *computeMe, Pipe *inPipe, Pipe *outPipe) : QueryPlanNode(groupby),
		inPipeId(inPipeId), outPipeId(outPipeId), groupAtts(groupAtts),
		computeMe(computeMe), inPipe(inPipe), outPipe(outPipe) {
}

void GroupByNode::Print(){
	cout<<"********\n";
	cout<<"Group By\n";
	cout<<"Input pipe ID "<<inPipeId<<endl;
	cout<<"Output pipe ID "<<outPipeId<<endl;
	cout<<"Grouping Attrbutes:\n";
	groupAtts->Print();
	cout<<"Grouping Function:\n";
	computeMe->Print();
	cout<<"********\n";
}

void GroupByNode::Execute(){
	gb.Use_n_Pages(RUN_LENGTH);
	gb.Run(*inPipe, *outPipe, *groupAtts, *computeMe);
}

void GroupByNode::Wait(){
	gb.WaitUntilDone();
}

void GroupByNode::Clean(){

}
